package net.mcreator.wastedworld.procedures;

import net.minecraft.world.IWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.Direction;
import net.minecraft.item.ItemStack;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.Entity;

import net.mcreator.wastedworld.item.SharpStoneItem;
import net.mcreator.wastedworld.item.CoalPieceItem;
import net.mcreator.wastedworld.block.CoalPowderBlock;
import net.mcreator.wastedworld.WastedWorldMod;

import java.util.Random;
import java.util.Map;

public class PlayerMakeCoalDustProcedure {
	public static void executeProcedure(Map<String, Object> dependencies) {
		if (dependencies.get("direction") == null) {
			if (!dependencies.containsKey("direction"))
				WastedWorldMod.LOGGER.warn("Failed to load dependency direction for procedure PlayerMakeCoalDust!");
			return;
		}
		if (dependencies.get("entity") == null) {
			if (!dependencies.containsKey("entity"))
				WastedWorldMod.LOGGER.warn("Failed to load dependency entity for procedure PlayerMakeCoalDust!");
			return;
		}
		if (dependencies.get("x") == null) {
			if (!dependencies.containsKey("x"))
				WastedWorldMod.LOGGER.warn("Failed to load dependency x for procedure PlayerMakeCoalDust!");
			return;
		}
		if (dependencies.get("y") == null) {
			if (!dependencies.containsKey("y"))
				WastedWorldMod.LOGGER.warn("Failed to load dependency y for procedure PlayerMakeCoalDust!");
			return;
		}
		if (dependencies.get("z") == null) {
			if (!dependencies.containsKey("z"))
				WastedWorldMod.LOGGER.warn("Failed to load dependency z for procedure PlayerMakeCoalDust!");
			return;
		}
		if (dependencies.get("world") == null) {
			if (!dependencies.containsKey("world"))
				WastedWorldMod.LOGGER.warn("Failed to load dependency world for procedure PlayerMakeCoalDust!");
			return;
		}
		Direction direction = (Direction) dependencies.get("direction");
		Entity entity = (Entity) dependencies.get("entity");
		double x = dependencies.get("x") instanceof Integer ? (int) dependencies.get("x") : (double) dependencies.get("x");
		double y = dependencies.get("y") instanceof Integer ? (int) dependencies.get("y") : (double) dependencies.get("y");
		double z = dependencies.get("z") instanceof Integer ? (int) dependencies.get("z") : (double) dependencies.get("z");
		IWorld world = (IWorld) dependencies.get("world");
		if ((((SharpStoneItem.block == ((entity instanceof LivingEntity) ? ((LivingEntity) entity).getHeldItemOffhand() : ItemStack.EMPTY).getItem())
				&& ((entity instanceof PlayerEntity) ? ((PlayerEntity) entity).inventory.hasItemStack(new ItemStack(CoalPieceItem.block)) : false))
				&& (Direction.UP == direction))) {
			if (entity instanceof PlayerEntity) {
				ItemStack _stktoremove = new ItemStack(CoalPieceItem.block);
				((PlayerEntity) entity).inventory.func_234564_a_(p -> _stktoremove.getItem() == p.getItem(), (int) 1,
						((PlayerEntity) entity).container.func_234641_j_());
			}
			{
				ItemStack _ist = ((entity instanceof LivingEntity) ? ((LivingEntity) entity).getHeldItemOffhand() : ItemStack.EMPTY);
				if (_ist.attemptDamageItem((int) 1, new Random(), null)) {
					_ist.shrink(1);
					_ist.setDamage(0);
				}
			}
			world.setBlockState(new BlockPos((int) x, (int) y, (int) z), CoalPowderBlock.block.getDefaultState(), 3);
		}
	}
}
